var _api = _interopRequireDefault(require("../../../../utils/api")), _util2 = _interopRequireDefault(require("../../../../public/utils/util")), _util3 = _interopRequireDefault(require("../util"));

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

function _objectSpread(e) {
    for (var t = 1; t < arguments.length; t++) {
        var i = null != arguments[t] ? arguments[t] : {}, a = Object.keys(i);
        "function" == typeof Object.getOwnPropertySymbols && (a = a.concat(Object.getOwnPropertySymbols(i).filter(function(t) {
            return Object.getOwnPropertyDescriptor(i, t).enumerable;
        }))), a.forEach(function(t) {
            _defineProperty(e, t, i[t]);
        });
    }
    return e;
}

function _defineProperty(t, e, i) {
    return e in t ? Object.defineProperty(t, e, {
        value: i,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[e] = i, t;
}

var MAX_WORD_COUNT = 200;

Page({
    data: {
        MAX_WORD_COUNT: MAX_WORD_COUNT,
        placeholder: "请输入客户跟进记录...",
        form: {
            content: "",
            alarmtime: ""
        },
        barTitle: "添加跟进记录",
        startTime: _util2.default.formatLocalDate(Date.now() + 18e5, "Y-M-D h:m"),
        pickerShown: !1
    },
    onLoad: function() {
        this.basics = this.$take("niche.add.record").query;
        var t = this.$take("record.data");
        t && this.setData({
            barTitle: "编辑跟进记录",
            "form.followid": t.id,
            "form.content": t.content,
            "form.alarmtime": t.alarmtime
        });
    },
    onInput: function(t) {
        this.setData({
            "form.content": t.detail.value
        });
    },
    onPickerShown: function() {
        this.setData({
            pickerShown: !0
        });
    },
    onTimeReset: function() {
        this.setData({
            "form.alarmtime": ""
        });
    },
    onTimeChange: function(t) {
        this.setData({
            "form.alarmtime": t.detail.value
        });
    },
    submit: function(t) {
        var e = this;
        wx.showLoading({
            mask: !0
        }), this.$app.collectFormId(t);
        var i = this.data.form, a = i.content, r = i.followid, n = i.alarmtime;
        (r ? _api.default.minicard.business.editfollow({
            data: {
                cardid: this.basics.cardid,
                followid: r,
                content: a,
                alarmtime: n
            }
        }).then(function() {
            return r;
        }) : _util3.default.addFollowRecord(_objectSpread({
            content: a,
            alarmtime: n,
            issystem: 0
        }, this.basics), wx.hideLoading).then(function(t) {
            return t.data;
        })).then(function(t) {
            e.$emit("niche.record.update", {
                content: a,
                alarmtime: n,
                data: t,
                issystem: 0
            }), wx.successTip({
                title: "保存成功",
                success: function() {
                    return e.$route("back");
                }
            });
        });
    }
});